<template>
  <el-dialog
    :title="title"
    :visible.sync="dialogFormVisible"
    :close-on-click-modal="false"
    width="500px"
    @close="close"
  >
    <el-form ref="form" :model="queryForm" label-width="80px">
      <el-form-item v-if="queryForm.exportType=='package'" label="组织">
        <el-checkbox-group v-model="checkboxGroup2">
          <el-checkbox label="加盟店" border></el-checkbox>
          <el-checkbox label="渠道店" border></el-checkbox>
      </el-checkbox-group>
      </el-form-item>
      <el-form-item v-if="queryForm.exportType=='package'" label="客户检索" prop="customerId">
          <el-select v-model="queryForm.customerId" placeholder="请检索客户" clearable filterable>
            <el-option
              v-for="(item, index) in customerList"
              :key="index"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="物流线路" prop="wuliuCode">
          <el-select v-model="queryForm.wuliuCode" placeholder="请选择物流线路" multiple clearable filterable>
            <el-option
              v-for="(item, index) in wuliuList"
              :key="index"
              :value="item.fnumber"
              :label="item.fdataValue"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="发货日期:">
            <el-date-picker
              v-model="value1"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :clearable="false"
            ></el-date-picker>
          </el-form-item>
      <el-form-item v-if="queryForm.exportType=='package'" label="全部导出" prop="allExport">
          <el-switch
              v-model="queryForm.allExport">
            </el-switch>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="save">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
const dayjs = require('dayjs')
import { baseURL } from '@/config/settings'
export default {
  name: 'PackageDialog',
  data() {
    return {
      checkboxGroup2:[],
      queryForm: {
        condition:[],
        customerId:null,
        wuliuCode:null,
        start: null,
        end: null,
        exportType:null,
        allExport:true
      },
      title: '',
      value1: [],
      wuliuList: [],
      customerList:[],
      dialogFormVisible: false,
    }
  },
  created() {},
  methods: {
    showDialog(wuliuList,exportType,approvedList) {
      this.queryForm.exportType = exportType
      this.wuliuList = wuliuList
      this.value1 = [new Date(),new Date()]
      if(exportType=="package"){
        this.title = "装箱导出条件筛选"
        this.customerList = approvedList
      }else{
        this.title = "司机送货专用单条件筛选"
      }
      this.dialogFormVisible = true
    },
    close() {
      try {
        this.$refs['form'].resetFields()
        this.form = this.$options.data().form
      } catch(e) {}
      this.checkboxGroup2 = []
      this.dialogFormVisible = false
    },
    save() {
      if(this.value1.length > 0){
        this.queryForm.start = dayjs(this.value1[0]).format('YYYY-MM-DD')
        this.queryForm.end = dayjs(this.value1[1]).format('YYYY-MM-DD')
      }

      this.queryForm.condition = []
      if(this.checkboxGroup2.indexOf('加盟店') > -1){
        this.queryForm.condition.push('Franchise')
      }
      if(this.checkboxGroup2.indexOf('渠道店') > -1){
        this.queryForm.condition.push('Channel')
      }

      let result =  Object.assign({}, this.queryForm)
      result.customerId = result.customerId || 0;
      let query = encodeURIComponent(JSON.stringify(result));
      location.href = baseURL + '/erp/order/exportERP?queryString=' + query

      //this.$emit('fetch-data')
      //this.close()
    },
  },
}
</script>
<style>
  .el-select {
    width: 100%;
  }
</style>
